//
package scrabble

import (
	"regexp"
	"strings"
)

const testVersion = 5

// ```plain
// Letter                           Value
// A, E, I, O, U, L, N, R, S, T       1
// D, G                               2
// B, C, M, P                         3
// F, H, V, W, Y                      4
// K                                  5
// J, X                               8
// Q, Z                               10
// ```
var regLetterValues1,
	regLetterValues2,
	regLetterValues3,
	regLetterValues4,
	regLetterValues5,
	regLetterValues8,
	regLetterValues10 = regexp.MustCompile(`[a|e|i|o|u|l|n|r|s|t]`),
	regexp.MustCompile(`[d|g]`),
	regexp.MustCompile(`[b|c|m|p]`),
	regexp.MustCompile(`[f|h|v|w|y]`),
	regexp.MustCompile(`[k]`),
	regexp.MustCompile(`[j|x]`),
	regexp.MustCompile(`[q|z]`)

// Score
func Score(input string) (score int) {
	s := strings.ToLower(input)
	score = len(regLetterValues1.FindAllString(s, -1))*1 +
		len(regLetterValues2.FindAllString(s, -1))*2 +
		len(regLetterValues3.FindAllString(s, -1))*3 +
		len(regLetterValues4.FindAllString(s, -1))*4 +
		len(regLetterValues5.FindAllString(s, -1))*5 +
		len(regLetterValues8.FindAllString(s, -1))*8 +
		len(regLetterValues10.FindAllString(s, -1))*10
	return
}
